package com.dingreading.cloud.admin.controller;

import com.dingreading.cloud.admin.service.CourseTrainCommonService;
import com.dingreading.cloud.common.base.R;
import com.dingreading.cloud.common.util.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/system/courseTrainFile")
@Api(tags = "总部-学院线下培训课程文件管理")
public class CourseTrainFileController {
    @Resource
    private CourseTrainCommonService courseTrainCommonService;

    @ApiOperation(value = "分页列表")
    @PostMapping(value = "/pageList", produces = "application/json; charset=UTF-8")
    public R<Object> pageList(
            @ApiParam(value = "分页公共类") PageUtil pageUtil,
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "视频名称") @RequestParam(value = "keyword", required = false) String keyword,
            @ApiParam(value = "课程Uid") @RequestParam(value = "lessonUid", required = false) String lessonUid,
            @ApiParam(value = "启用状态") @RequestParam(value = "enabled", required = false) Integer enabled
    ) {
        return courseTrainCommonService.pageFileList(pageUtil, headStaffUid, headStaffName, keyword, lessonUid, enabled);
    }

    @ApiOperation(value = "新增/修改课程文件")
    @PostMapping(value = "/newFile")
    public R<Object> newFile(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "文件Uid") @RequestParam(value = "uid", required = false) String uid,
            @ApiParam(value = "课程Uid") @RequestParam(value = "lessonUid") String lessonUid,
            @ApiParam(value = "视频名称") @RequestParam(value = "name") String name,
            @ApiParam(value = "视频地址") @RequestParam(value = "url") String url,
            @ApiParam(value = "视频总时长/秒") @RequestParam(value = "videoDuration", required = false) Integer videoDuration
    ) {
        return courseTrainCommonService.newFile(headStaffUid, headStaffName, uid, lessonUid, name, url, videoDuration);
    }

    @ApiOperation(value = "根据UID获取信息")
    @PostMapping(value = "/getByUid", produces = "application/json; charset=UTF-8")
    public R<Object> getByUid(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "文件Uid") @RequestParam(value = "uid") String uid
    ) {
        return courseTrainCommonService.getFileByUid(headStaffUid, headStaffName, uid);
    }

    @ApiOperation(value = "更新文件启用状态")
    @PostMapping(value = "/updateEnabled", produces = "application/json; charset=UTF-8")
    public R<Object> updateEnabled(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "文件Uid") @RequestParam(value = "uid") String uid,
            @ApiParam(value = "状态 0.禁用 1.启用") @RequestParam(value = "enabled") Integer enabled
    ) {
        return courseTrainCommonService.updateFileEnabled(headStaffUid, headStaffName, uid, enabled);
    }

    @ApiOperation(value = "根据课程UID获取所有文件")
    @PostMapping(value = "/getByLessonUid", produces = "application/json; charset=UTF-8")
    public R<Object> getByLessonUid(
            @ApiParam(value = "总部员工uid") @RequestParam(value = "headStaffUid") String headStaffUid,
            @ApiParam(value = "总部员工名") @RequestParam(value = "headStaffName") String headStaffName,
            @ApiParam(value = "课程Uid") @RequestParam(value = "lessonUid") String lessonUid
    ) {
        return courseTrainCommonService.getFileByLessonUid(headStaffUid, headStaffName, lessonUid);
    }

}
